$(() => {
  let $width = $('#width'),
      $height = $('#height'),
      $btnCal = $('#calc'),
      
      $perimeter = $('#perimeter'),
      $area = $('#area');
  
  /* calc button click */
  $btnCal.click(() => {
    let w = Number($width.val());
    let h = Number($height.val());

    // get value
  
    //calc
    let p = (w+h)*2,
        a = w * h;
    
    //solve
    function l1(x,n){
      return Math.round(x * Math.pow(10,n)) / Math.pow(10,n);
    }
    
    let m1,m2;
    try{
      m1 = w.toString().split('.')[1].length;
    }catch(e){
      m1 = 0;
    }
    try{
      m2 = h.toString().split('.')[1].length;
    }catch(e){
      m2 = 0;
    }

  
    //output
    $perimeter.val(l1(p,Math.max(m1,m2)));
    $area.val(l1(a,m1+m2));
  });  
});
